﻿import {
    useCallback,
    useEffect,
    useState
} from "react";

import { httpGetPlanets } from "./request";

function usePlanets(){
    const [planets, setPlanets] = useState([]);

    const getPlanets = useCallback(async ()=>{
        const fetchedPlanets = await httpGetPlanets();
        setPlanets(fetchedPlanets);
    },[]);

    useEffect(() => {
        getPlanets();
    },[getPlanets]);

    return planets;
}

export default usePlanets;
